// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import axios from 'axios'
import router from './router'
import FastClick from 'fastclick'
import "./common/stylus/index.styl"
import 'swiper/dist/css/swiper.min.css'
import './filter/index'
import vConsole from 'vConsole'
// let vConsolemm = new vConsole()
import Vant from 'vant';
import 'vant/lib/index.css';
import '../static/css/reset.css';
import store from './store'

Vue.use(Vant);

// if (process.env.NODE_ENV === 'development') {
//   const VConsole = require('vconsole')
//   new VConsole()
// }
let u = navigator.userAgent;
let isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
function appEventTrigger(type) {
  if ("back" == type) {
    back();
  }
  if ("jsAPIReady" === type) {
    var event = document.createEvent('HTMLEvents');
    // 3个参数：事件类型，是否冒泡，是否阻止浏览器的默认行为
    event.initEvent(type, true, true);

    document.dispatchEvent(event);
  }
}

if (window.BmacJSBridge) {
  start && start();
} else {
  document.addEventListener('BmacJSBridgeReady', start, false); //这里调的下面那个函数  这是个函数名
}

function start() {

  Vue.prototype.BmacJSBridge = window.BmacJSBridge // 配置全局jsAPI,用来调用客户端方法，内部组件jsAPI使用
  BmacJSBridge.call('obtainClientBaseUrl', (data) => {
    try {
      initSensors(data.sensersUrl, data.environment, window.BmacJSBridge)
        .then(stratagemBurialPoint => {
          Vue.prototype.$tarckFun = stratagemBurialPoint.track
          Vue.prototype.$setPage = stratagemBurialPoint.sensors
          createApp();
        })
        .catch(error => {
          console.log('神策埋点失败1123');
          createApp();
        });
    } catch (error) {
      console.log('神策埋点失败11212312312');
      createApp();
    }
    if (data.isProd == 0) {
      new vConsole();
    }
  });
}
function createApp() {
  new Vue({
    el: '#app',
    router,
    store,
    components: {
      App
    },
    template: '<App/>',
  });
}
Vue.prototype.$ajax = axios // 配置全局$ajax发送请求，this.$ajax使用

// 代码里得区分下本地开发环境和生产环境
Vue.config.productionTip = false

/* eslint-disable no-new */


if ('addEventListener' in document) { // 解决300毫秒延时和透点问题
  document.addEventListener('DOMContentLoaded', function () {
    FastClick.attach(document.body);
  }, false);
}
// start(); // 打包的时候注释掉
